package com.dfbz.dao;

import com.dfbz.entity.Userfocus;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

public class UserfocusdDao extends BaseDao{

    public Userfocus findAttention(long uid, long fid) {
        try {
            return jdbcTemplate.queryForObject("select * from userfocus where user_id = ? and user_focus_id = ?",new BeanPropertyRowMapper<>(Userfocus.class),uid,fid);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }

    public void addUserfocus(long uid, long fid) {
        jdbcTemplate.update("insert into userfocus values(?,?)",uid,fid);
    }

    public void removeUserfocus(long uid, long fid) {
        jdbcTemplate.update("delete from userfocus where user_id = ? and user_focus_id = ?",uid,fid);
    }
    public List<Userfocus> findFansListById(Long id) {
        try {
            return jdbcTemplate.query("select * from userfocus where user_id = ?",new BeanPropertyRowMapper<>(Userfocus.class),id);
        } catch (EmptyResultDataAccessException e) {
            return null;
        }
    }
}
